<template>
  <div class="add box">
    <div>
      <p>
        <i class="icon-bitian iconfont"></i>业务名称
        <el-input v-model="name" placeholder="请输入业务名称" maxlength="30" size="normal"></el-input>
      </p>
      <p>
        <i class="icon-bitian iconfont"></i>所属系统
        <el-select v-model="sysId" placeholder="请选择系统名称" size="normal">
          <el-option
              v-for="item in systemList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
          </el-option>
        </el-select>
      </p>
      <p>
        <i class="icon-bitian iconfont"></i>传输配置
        <el-select v-model="transmissionId" placeholder="请选择传输配置" size="normal">
          <el-option
              v-for="item in transmissionList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
          </el-option>
        </el-select>
      </p>
      <p>
        &#12288;&#12288;&#12288;备注
        <el-input
            size="normal"
            type="textarea"
            maxlength="100"
            :autosize="{ minRows: 2, maxRows: 4}"
            placeholder="请输入内容"
            v-model="remarks"
            resize="none">
        </el-input>
      </p>
      <p>
        <el-button type="primary" round size="normal" @click="addBusiness">确认</el-button>
        <el-button round size="normal" @click="()=>{$router.push('/configManage/businessManage')}">取消</el-button>
      </p>
    </div>

  </div>
</template>

<script>
export default {
  name: "businessAdd",
  components:{},
  data(){
    return{
      systemList:[],
      transmissionList:[],
      transmissionId:'',
      sysId:'',
      name:'',
      remarks:''
    }
  },
  created() {
    this.getSystemList();
    this.getTransmissionList();
  },
  methods:{
    getSystemList(){
      this.$Http.systemListAll().then(res => {
        this.systemList = res.data;
      })
    },
    getTransmissionList(){
      this.$Http.transmissionListAll().then(res => {
        this.transmissionList = res.data;
      })
    },
    verify(){
      if(this.name ===""){
        this.$message.error("请填写业务名称");
        return false;
      }
      else if(this.name.length>30){
        this.$message.error("请填写正确格式的业务名称，不能超30个字符");
        return false;
      }
      else if(this.sysId ===""){
        this.$message.error("请选择所属系统");
        return false;
      }
      else if(this.transmissionId ===""){
        this.$message.error("请选择传输配置");
        return false;
      }
      else if(this.remarks.length>100){
        this.$message.error("请重新填写备注，不能超100个字符");
        return false;
      }
      else if(this.sysId ===""&&this.remarks ===""&&this.name ===""&&this.transmissionId ===""){
        this.$message.error("请填写所有信息");
        return false;
      }
      else{
        return true;
      }
    },
    addBusiness() {
      if(this.verify()){
        this.$Http.businessAdd({
          sysId:this.sysId,
          remarks:this.remarks,
          name:this.name,
          transmissionId:this.transmissionId
        }).then(res => {
          if(res.code === "SUCCESS"){
            this.$message.success("添加成功");
            this.$router.push('/configManage/businessManage');
          }
          else{
            this.$message.error(res.message);
          }
        })
      }
    }

  }
}
</script>

<style scoped lang="scss">
@import "src/assets/css/content.scss";

</style>
